From 290c0e61a1a065a53f3173451c151811f7cc4684 Mon Sep 17 00:00:00 2001 From: tsteven4 <13596209+tsteven4@users.noreply.github.com> Date: Sat, 29 Jan 2022 14:45:30 -0700 Subject: [PATCH] convert Mapbar track to Format class (#841) * convert mapbar_track to Format class. * const member funcs --- CMakeLists.txt | 1 + GPSBabel.pro | 1 + mapbar_track.cc | 55 +++++++++----------------------- mapbar_track.h | 85 +++++++++++++++++++++++++++++++++++++++++++++++++ vecs.h | 4 +-- 5 files changed, 104 insertions(+), 42 deletions(-) create mode 100644 mapbar_track.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 616d385e3..07d53e048 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -249,6 +249,7 @@ set(HEADERS legacyformat.h lowranceusr.h magellan.h + mapbar_track.h mapfactor.h mynav.h navilink.h diff --git a/GPSBabel.pro b/GPSBabel.pro index 6a1ada81e..975b01748 100644 --- a/GPSBabel.pro +++ b/GPSBabel.pro @@ -236,6 +236,7 @@ HEADERS = \ legacyformat.h \ lowranceusr.h \ magellan.h \ + mapbar_track.h \ mapfactor.h \ mynav.h \ navilink.h \ diff --git a/mapbar_track.cc b/mapbar_track.cc index 002c8867c..25df919da 100644 --- a/mapbar_track.cc +++ b/mapbar_track.cc @@ -21,45 +21,40 @@ */ -#include // for SEEK_CUR +#include "mapbar_track.h" #include // for QChar #include // for QDate #include // for QString #include // for QTime -#include // for QVector -#include "defs.h" -#include "gbfile.h" // for gbfgetint16, gbfgetint32, gbfseek, gbfclose, gbfopen, gbfile +#include // for SEEK_CUR + +#include "defs.h" // for fatal, Waypoint, track_add_head, track_add_wpt, route_head +#include "gbfile.h" // for gbfgetint16, gbfgetint32, gbfseek, gbfclose, gbfopen #include "src/core/datetime.h" // for DateTime #define MYNAME "mapbar_track" -static gbfile* fin; - -static -QVector mapbar_track_args = { -}; - /******************************************************************************* * %%% global callbacks called by gpsbabel main process %%% * *******************************************************************************/ -static void -mapbar_track_rd_init(const QString& fname) +void +MapbarTrackFormat::rd_init(const QString& fname) { fin = gbfopen(fname, "r", MYNAME); } -static void -mapbar_track_rd_deinit() +void +MapbarTrackFormat::rd_deinit() { gbfclose(fin); } -static gpsbabel::DateTime -read_datetime() +gpsbabel::DateTime +MapbarTrackFormat::read_datetime() const { int hour = gbfgetint16(fin); int min = gbfgetint16(fin); @@ -71,9 +66,8 @@ read_datetime() return t; } -static const double DIV_RATE = 100000.0f; -static Waypoint* -read_waypoint() +Waypoint* +MapbarTrackFormat::read_waypoint() const { int longitude = gbfgetint32(fin); int latitude = gbfgetint32(fin); @@ -86,8 +80,8 @@ read_waypoint() return ret; } -static void -mapbar_track_read() +void +MapbarTrackFormat::read() { auto* track = new route_head; track_add_head(track); @@ -134,22 +128,3 @@ mapbar_track_read() end_flag = gbfgetint32(fin); } } - -// capabilities below means: we can only read trackpoints. - -ff_vecs_t mapbar_track_vecs = { - ff_type_file, - { ff_cap_none, (ff_cap)(ff_cap_read), ff_cap_none }, - mapbar_track_rd_init, - nullptr, - mapbar_track_rd_deinit, - nullptr, - mapbar_track_read, - nullptr, - nullptr, - &mapbar_track_args, - CET_CHARSET_UTF8, 0 - /* not fixed, can be changed through command line parameter */ - , NULL_POS_OPS, - nullptr -}; diff --git a/mapbar_track.h b/mapbar_track.h new file mode 100644 index 000000000..b522a5593 --- /dev/null +++ b/mapbar_track.h @@ -0,0 +1,85 @@ +/* + China mapbar navigation track reader for sonim xp3300 + it's maybe can used in other demo devices of mapbar navigation + + Copyright (C) 2013 xiao jian cheng, azuresky.xjc@gmail.com + Copyright (C) 2001-2013 Robert Lipe, robertlipe+source@gpsbabel.org + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + + */ +#ifndef MAPBAR_TRACK_H_INCLUDED_ +#define MAPBAR_TRACK_H_INCLUDED_ + +#include // for QString +#include // for QVector + +#include "defs.h" // for ff_cap, arglist_t, ff_cap_none, CET_CHARSET_UTF8, Waypoint, ff_cap_read, ff_type, ff_type_file +#include "format.h" // for Format +#include "gbfile.h" // for gbfile +#include "src/core/datetime.h" // for DateTime + + +class MapbarTrackFormat : public Format +{ +public: + QVector* get_args() override + { + return &mapbar_track_args; + } + + ff_type get_type() const override + { + return ff_type_file; + } + + QVector get_cap() const override + { + /* waypoints, tracks, routes */ + return { ff_cap_none, (ff_cap)(ff_cap_read), ff_cap_none }; + } + + QString get_encode() const override + { + return CET_CHARSET_UTF8; + } + + int get_fixed_encode() const override + { + return 0; + } + + void rd_init(const QString& fname) override; + void read() override; + void rd_deinit() override; + +private: + /* Constants */ + + static constexpr double DIV_RATE = 100000.0f; + + /* Member Functions */ + + gpsbabel::DateTime read_datetime() const; + Waypoint* read_waypoint() const; + + /* Data Members */ + + gbfile* fin{}; + + QVector mapbar_track_args = { + }; +}; +#endif // MAPBAR_TRACK_H_INCLUDED_ diff --git a/vecs.h b/vecs.h index e82dc6b7f..5ef98f333 100644 --- a/vecs.h +++ b/vecs.h @@ -42,6 +42,7 @@ #include "kml.h" #include "legacyformat.h" #include "lowranceusr.h" +#include "mapbar_track.h" #include "mapfactor.h" #include "mynav.h" #include "nmea.h" @@ -125,7 +126,6 @@ extern ff_vecs_t mmo_vecs; extern ff_vecs_t v900_vecs; extern ff_vecs_t enigma_vecs; extern ff_vecs_t format_garmin_xt_vecs; -extern ff_vecs_t mapbar_track_vecs; extern ff_vecs_t f90g_track_vecs; #endif // MAXIMAL_ENABLED @@ -319,7 +319,7 @@ private: SubripFormat subrip_fmt; LegacyFormat format_garmin_xt_fmt {format_garmin_xt_vecs}; GarminFitFormat format_fit_fmt; - LegacyFormat mapbar_track_fmt {mapbar_track_vecs}; + MapbarTrackFormat mapbar_track_fmt; LegacyFormat f90g_track_fmt {f90g_track_vecs}; MapfactorFormat mapfactor_fmt; EnergymproFormat energympro_fmt; -- 2.30.2